import request from '@/utils/http'

interface GongYiJieDianResult {
  id: string
  name: string
  order: number
  parentId: any
  belong: number
  materialCraftNodeName: any
  energyCraftNodeName: any
}

interface BanCXinXiResult {
  machineDocumentId: string
  craftNodeId: string
  tsId: number
  shiftName: string
  teamSet: string
  shiftNum: number
  shiftOrder: number
  begin: string
  end: string
}

interface GetJiChuBaoBiaoGongXuResult {
  id: string
  name: string
  order: number
  parentId: any
  belong: number
  materialCraftNodeName: any
  energyCraftNodeName: any
}

export interface GetBanCiResult {
  craftNodeId: string
  shiftName: string
  shiftOrder: string
}

interface GetJiTaiTheGongYiResult {
  id: string
  tenantId: string
  craftNodeId: string
  collectDriveId: string
  collectDriveName: string
  collectVersionId?: string
  collectAgreementId: any
  collectAgreementName: any
  powerCollectAgreementName: any
  spindleXSCollectAgreementName: any
  craftNodeName: string
  materialCraftNodeName: string
  craftNodeOrder: number
  machineTypeId: number
  machineTypeName: string
  machineTypeDescription: string
  machineNo: number
  machineName: string
  ip: string
  slubIp: any
  modbusAddr: number
  colletcVersion?: string
  yarnBreakDetection: number
  spindleNums: number
  periodModel: any
  segmentedNums?: number
  manufacturerId: string
  manufacturerName: string
  textileMillName: string
  textileGroupName: string
  textileMillCode: string
  databaseAccount: any
  databasePassword: any
  databasePath: any
  port: number
  source: number
  powerSign: boolean
  powerSource: number
  powerMachineTypeId: any
  powerCollectVersionId: any
  powerCollectAgreementId: any
  spindleXSCollectAgreementId: any
  spindleIp: any
  powerIp: any
  powerAddr: any
  powerIndividualLoad: any
  powerLoadNumber: any
  cbf: any
  energyStructureId: any
  machineGatherCycle?: number
  machineInstructionCycle?: number
  energyGatherCycle: any
  energyInstructionCycle: any
  collectVersionSlubId: any
  collectAgreementSlubId: any
  slubSign: any
}

interface GetGongXuBuDaiFuJiResult {
  id: string
  name: string
  order: number
  parentId: any
  belong: number
  materialCraftNodeName: any
  energyCraftNodeName: any
}

export interface GetDangQianBanCiResult {
  /** 机台id */
  machineDocumentId: string
  /** 工艺节点 或者 区域ID */
  craftNodeId: string
  /** 班次号 */
  tsId: number
  /** 班别 */
  shiftName: string
  /** 班组 */
  teamSet: any
  /** 上班次号 */
  tsIdLast: number
  /** 上班别 */
  shiftNameLast: string
  /** 上班组 */
  teamSetLast: any
  /** 班号 */
  shiftNum: number
  /** 序号 */
  shiftOrder: number
  /** 开始时间 */
  begin: string
  /** 结束时间 */
  end: string
  /** 执行换班时间 */
  updateTime: string
  /** 是否生成了停车日报，true表示已经生成了上班次班报 */
  machineRunlogFlag: boolean
  /** 上个班次持续时间 */
  shiftDurationLast: number
}

// 获取纺纱车间络筒、细纱工序的实时开台数据
export function GetOpenDataBySpinningMillId(SpinningMillId) {
  return request.request({
    url: '/DeviceInfo/GetOpenDataBySpinningMillId?SpinningMillId=' + SpinningMillId,
    method: 'get'
  })
}

// 根据工艺节点、班次,获取期间所有在纺品种
export function getgongYiBanCiGetWuLiaoList(param: {
  craftNodeName: string | number
  tsidStart: string | number
  tsidEnd: string | number
}) {
  return request.request<{ materialId: string; materialName: string }[]>({
    url:
      '/api/v3.1/business/shift-report-condition/material-by-tsid?craftNodeName=' +
      param.craftNodeName +
      '&tsidStart=' +
      param.tsidStart +
      '&tsidEnd=' +
      param.tsidEnd,
    method: 'get'
  })
}
//  根据区域id,工艺节点、班次，获取期间所有在纺品种
export function getHuoQuShuoYouZaiFangPingZhong_qy(data: {
  areaId: string
  craftNodeName: string
  tsidStart: string
  tsidEnd: string
}) {
  return request.request({
    url:
      '/api/v3.1/business/shift-report-condition/material-by-tsid-and-area/' +
      data.areaId +
      '?craftNodeName=' +
      data.craftNodeName +
      '&tsidStart=' +
      data.tsidStart +
      '&tsidEnd=' +
      data.tsidEnd,
    method: 'get'
  })
}
// 根据工艺接口和时间获取班次
export function getbanCi(data: { craftNodeId: string; start: string }) {
  return request.request<GetBanCiResult[]>({
    url:
      '/api/v3.1/business/shift-info-utils/shift-roll/' + data.craftNodeId + '?start=' + data.start,
    method: 'get'
  })
}
//  根据区域id、时间，获取轮班信息
export function getbanCi_qy(data: { areaId: string; start: string }) {
  return request.request<GetBanCiResult[]>({
    url:
      '/api/v3.1/business/shift-info-utils/shift-roll-by-area-id/' +
      data.areaId +
      '?start=' +
      data.start,
    method: 'get'
  })
}
// 获取指定车间下实时物料和机台的tree结构
export function getJiTaiAndWuLiao() {
  return request.request({
    url: '/api/v3.1/business/position-info/machine-material',
    method: 'get'
  })
}
/**
 * 查询车间所有装有单锭检测的机台和对应的物料
 */
export function getDingSuAndQianDingShiDuanTou() {
  return request.request({
    url: '/api/v3.1/business/position-info/machine-material',
    method: 'get'
  })
}
// 根据工艺节点获取机台数据
export function getJiTaiTheGongYi(gongYiID: string) {
  return request.request<GetJiTaiTheGongYiResult[]>({
    url: '/api/v3.0/basic/machine-document/by-craft-node-machine-type-list?craftNodeId=' + gongYiID,
    method: 'get'
  })
}

// 根据工艺节点集合获取对应的分组设备信息
export function getJiTaiByCraftNodeIds(data) {
  return request.request({
    url: '/api/v3.0/basic/machine-document/get-by-craft-node-ids-machine-list',
    method: 'post',
    data
  })
}

// 络筒织机根据工艺节点获取机台数据
export function getLuoTongZhiJiJiTaiTheGongYi(name) {
  return request.request({
    url: '/api/v3.0/basic/machine-document/by-craft-node-machine-type-list?craftNodeName=' + name,
    method: 'get'
  })
}

//  查询出所以工艺节点(不包含作为父级的)
export function allGongXu() {
  return request.request<GongYiJieDianResult[]>({
    url: '/api/v3.0/basic/craft-node/park-craft-list',
    method: 'get'
  })
}

// 获取指定车间工艺节点列表
export function getGongYiJieDianList() {
  return request.request({
    url: '/api/v3.0/basic/craft-node/only-craft-list',
    method: 'get'
  })
}

// 获取排班工序列表
export function getGongYiReportList() {
  return request.request({
    url: '/api/v3.0/basic/craft-node/report-craft-list',
    method: 'get'
  })
}

// 指定工艺节点，获取所有备选的物料信息
export function getWuLiaoList(gonYiID) {
  return request.request({
    url: '/api/v3.1/business/material/by-nodelist/' + gonYiID,
    method: 'get'
  })
}

//  根据工艺节点、时间，获取上一个班次的班次信息(工序id)
export function getBanCiXinXi(data: { CraftNodeID: string; dateTime: string }) {
  return request.request<BanCXinXiResult>({
    url:
      '/api/v3.1/business/shift-info-utils/last-shiftinfo?CraftNodeList=' +
      data.CraftNodeID +
      '&dateTime=' +
      data.dateTime +
      '&isActiveTenant=0',
    method: 'get'
  })
}

// 根据工艺节点、时间，获取上一个班次的班次信息(工序名称)
export function getBanCiXinXiandGongXuName(data) {
  return request.request({
    url:
      '/api/v3.1/business/shift-info-utils/last-shift-info-by-craft-node?craftNodeName=' +
      data.name +
      '&dateTime=' +
      data.dateTime +
      '&isActiveTenant=true',
    method: 'get'
  })
}

// 获取织机工艺节点id
export function getZhiJiGongYiId() {
  return request.request({
    url: '/api/v3.1/business/loom-machine-shift-report/loom-craft-node-id',
    method: 'get'
  })
}

// 获取络筒工艺节点id
export function getLuoTongGongYiId() {
  return request.request({
    url: '/api/v3.1/business/lt-third-machine-shift-repord/lt-third-craft-node-id',
    method: 'get'
  })
}

// 查询所有工种
export function getGongZhongHuoQu(name: string) {
  return request.request<{ title: string; sort: number; id: string }[]>({
    url: '/api/v3.1/business/job-title-record?name=' + name,
    method: 'get'
  })
}

// 根据工艺节点Id获取当前班次信息和上班班次号，上班班组
export function getDangQianBanCi(data: { craftNodeId: string }) {
  return request.request<GetDangQianBanCiResult>({
    url: '/api/v3.1/business/shift-info-utils/current-shift-info/' + data.craftNodeId,
    method: 'get'
  })
}
// 根据工艺节点名称获取当前班次信息和上班班次号，上班班组
export function getDangQianBanCAndName(data) {
  return request.request({
    url:
      '/api/v3.1/business/shift-info-utils/current-shift-info?craftNodeName=' + data.craftNodeName,
    method: 'get'
  })
}

// 根据工艺节点和大机型获取机台列表
export function getDaJiXingAndJiTaiList(data) {
  return request.request({
    url: '/api/v3.1/business/device-info/machinelist-by-textileprocess/' + data.TextileId,
    method: 'get'
  })
}

// 根据车间ID获取大机型信息
export function getGenJuCheJianIDHuoQuDaJiXing() {
  return request.request({
    url: '/api/v3.1/business/textile-process',
    method: 'get'
  })
}

// 根据车间ID获取大机型和小机型信息
export function getHuoQuDaJiXingAndXiaoJiXingXinXi() {
  return request.request({
    url: '/api/v3.0/basic/craft-node-machine-type-tenant-association/machine-type-by-only-craft-node',
    method: 'get'
  })
}

// 根据车间ID获取所有品种
export function getHuoQuSuoYouPingZhong() {
  return request.request({
    url: '/api/v3.1/business/article-record',
    method: 'get'
  })
}
//  前端基础报表中工序查询(带产量的工序)
export function getJiChuBaoBiaoGongXu() {
  return request.request<GetJiChuBaoBiaoGongXuResult[]>({
    url: '/api/v3.0/basic/craft-node/no-production-list',
    method: 'get'
  })
}

//  前端仪器维护物料节点名称查询
export function getYiQiWeiHuList() {
  return request.request({
    url: '/api/v3.0/basic/craft-node/material-craft-node-list',
    method: 'get'
  })
}
// 前端仪器维护物料节点分组显示
export function getYiQiWuLiaoFenZuXianShi() {
  return request.request({
    url: '/api/v3.0/basic/craft-node/material-with-craft-node-list',
    method: 'get'
  })
}

//  前端工序查询(不带辅机和物流 只查工艺的工序)
export function getGongXuBuDaiFuJi() {
  return request.request<GetGongXuBuDaiFuJiResult[]>({
    url: '/api/v3.0/basic/craft-node/only-craft-list',
    method: 'get'
  })
}

//  前端故障诊断工序查询(不带辅机和物流 只查工艺的工序)
export function getGongXuBuDaiFuJi_gzzd() {
  return request.request({
    url: '/api/v3.0/basic/craft-node/warning-craft-list',
    method: 'get'
  })
}

//  获取指定工序下的当前在纺物料
export function getGongXuAndWuLiaoBiao(craftNodeName) {
  return request.request({
    url: '/api/v3.1/business/device-info/current-material?craftNodeName=' + craftNodeName,
    method: 'get'
  })
}

//  指定机台，查询在纺品种信息
export function getCurrentMaterialByMachine(machineDocumentId) {
  return request.request({
    url: '/api/v3.1/business/device-info/current-material-by-machine/' + machineDocumentId,
    method: 'get'
  })
}

//  指定机台，查询该设备所在工艺节点下的所有品种
export function getMaterialByMachineCraftNode(machineDocumentId) {
  return request.request({
    url: '/api/v3.1/business/device-info/material-by-craft-node/' + machineDocumentId,
    method: 'get'
  })
}

//  工艺节点获取机型
export function getgongYiJieDianHuoQUJiXing(craftNodeld) {
  return request.request({
    url:
      '/api/v3.0/basic/craft-node-machine-type-tenant-association/machine-type-tenant-association-list?craftNodeId=' +
      craftNodeld +
      '&isActiveTenant=true',
    method: 'get'
  })
}

//  获取租户绑定的停车类型
export function getTingCheLeiXing(craftNodeId) {
  return request.request({
    url: '/api/v3.0/basic/park-type/tenant-bind-park-type?craftNodeId=' + craftNodeId,
    method: 'get'
  })
}

//  指定页面代码，查询该页的用户使用习惯
export function getYongHuShiYongXiGuan(pageCode) {
  return request.request({
    url: '/api/v3.1/business/user-usage-habit/user-usage-habit?pageCode=' + pageCode,
    method: 'get'
  })
}

//  新建用户使用习惯
export function postYongHuShiYongXiGuan(data) {
  return request.request({
    url: '/api/v3.1/business/user-usage-habit/user-usage-habit',
    method: 'post',
    data
  })
}

//  修改用户使用习惯
export function putYongHuShiYongXiGuan(id, data) {
  return request.request({
    url: '/api/v3.1/business/user-usage-habit/' + id + '/user-usage-habit',
    method: 'put',
    data
  })
}

//  删除用户使用习惯
export function deleteYongHuShiYongXiGuan(id) {
  return request.request({
    url: '/api/v3.1/business/user-usage-habit/' + id + '/user-usage-habit',
    method: 'delete'
  })
}

//  根据班次号TsId、工艺节点，获取详细的班次信息
export function getXiangXiBanCiXingXi(data) {
  return request.request({
    url:
      '/api/v3.1/business/shift-info-utils/by-craft-node-and-tsid/' +
      data.CraftNodeListId +
      '?Tsid=' +
      data.Tsid,
    method: 'get'
  })
}

//  根据工序和编码 查询是否配置采集
export function postPeiZhiCaiJiChaXun(data) {
  return request.request({
    url: '/api/v3.0/basic/collect-meta/collect-meta-with-craft-node',
    method: 'post',
    data
  })
}

//  创建或者修改 重复断头配置
export function postChongFuDuanTouPeiZhi(data) {
  return request.request({
    url: '/api/v3.0/basic/break-cnt-repeat-config/or-update',
    method: 'post',
    data
  })
}

//  获取重复断头配置
export function getHuoQuChongFuDuanTouPeiZhi() {
  return request.request({
    url: '/api/v3.0/basic/break-cnt-repeat-config/break-cnt-repeat-config',
    method: 'get'
  })
}

//  获取集团重复断头配置
export function getHuoQuJiTuanChongFuDuanTouPeiZhi() {
  return request.request({
    url: '/api/v3.0/basic/break-cnt-repeat-config/mom-break-cnt-config',
    method: 'get'
  })
}

//  判断车间上级是否有集团
export function getPanDuanShiFouYouJiTuan() {
  return request.request({
    url: '/api/v3.0/basic/tenant-textile-mill/has-group',
    method: 'get'
  })
}

// 根据区域id、时间，获取上一个班次的班次信息
export function getHuoQuShangYiBanCiXinXi_qy(data) {
  return request.request({
    url:
      '/api/v3.1/business/shift-info-utils/last-shift-info-by-area-id?areaId=' +
      data.areaId +
      '&dateTime=' +
      data.dateTime +
      '&isActiveTenant=0',
    method: 'get'
  })
}

// 根据区域id和工艺节点id获取对应的设备信息
export function getHuoQuDuiYingSheBeiXinXi_qy(data: { areaId: string; craftNodeId: string }) {
  return request.request<GetJiTaiTheGongYiResult[]>({
    url:
      '/api/v3.1/business/shift-change-area-machine-asso/machine-list-by-area-id?areaId=' +
      data.areaId +
      '&craftNodeId=' +
      data.craftNodeId,
    method: 'get'
  })
}

// 指定日期，查询所在月的月报设置
export function getChaXunYueBaoSheZhi_day(tsidDay) {
  return request.request({
    url:
      '/api/v3.1/business/intenvory-month-report-set/intenvory-month-report-set-by-tsid-day?tsidDay=' +
      tsidDay,
    method: 'get'
  })
}

// 指定月份，查询月报设置
export function getChaXunYueBaoSheZhi_month(yearMonth) {
  return request.request({
    url:
      '/api/v3.1/business/intenvory-month-report-set/intenvory-month-report-set-by-year-month?yearMonth=' +
      yearMonth,
    method: 'get'
  })
}

// 获取租户已经配置过的工序
export function getPeiZhiGuoDeGongXu() {
  return request.request({
    url: '/api/v3.0/basic/alarm/craft-node-list',
    method: 'get'
  })
}
